<template>
    <div class="article-lists">
        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <router-link v-perms="['article.article/add', 'wenxin.wenxin/add:edit']" :to="{
                    path: getRoutePath('wenxin.wenxin/add:edit')
                }">
                    <el-button type="primary" class="mb-4">
                        <template #icon>
                            <icon name="el-icon-Plus" />
                        </template>
                        新增
                    </el-button>
                </router-link>
            </div>
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="温馨提示" prop="value" min-width="80" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button v-perms="['wenxin.wenxin/add:edit', 'wenxin.wenxin/add:edit']" type="primary" link>
                            <router-link :to="{
                                path: getRoutePath('wenxin.wenxin/add:edit'),
                                query: {
                                    id: row.id
                                }
                            }">
                                编辑
                            </router-link>
                        </el-button>
                        <el-button v-perms="['article.article/delete']" type="danger" link @click="handleDelete(row.id)">
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
          <!--  <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div> -->
        </el-card>
    </div>
</template>
<script lang="ts" setup name="getwen">
import { articleLists, articleDelete, articleStatus, articleCateAll,getwen,getAll,getdel ,getwenxinAdd} from '@/api/article'
import { useDictOptions } from '@/hooks/useDictOptions'
import { usePaging } from '@/hooks/wenxin'
import { getRoutePath } from '@/router'
import feedback from '@/utils/feedback'
const queryParams = reactive({
    title: '',
    cid: '',
    is_show: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: getwen,
    params: queryParams
})

const { optionsData } = useDictOptions<{
    article_cate: any[]
}>({
    article_cate: {
        api: getAll
    }
})

const changeStatus = async (is_show: any, id: number) => {
    try {
        await articleStatus({ id, is_show })
        getLists()
    } catch (error) {
        getLists()
    }
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await getdel({ id })
    getLists()
}

onActivated(() => {
    getLists()
})

getLists()
</script>
